package com.cagtwitter.services;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.cagtwitter.hibernate.Celebrity;
import com.cagtwitter.hibernate.CelebrityDao;

public class UIServices {
	public String getCarouselCelebTweetAsJson(){
		CelebrityDao hbc = new CelebrityDao();
		JSONArray resultJson = new JSONArray();
		MiscServices miscServ = new MiscServices();
		int quantity = 5;
		ArrayList<Integer> randomNumbers = miscServ.generateRandomNumbers(quantity,0,9);
		
		List<Celebrity> celebrities = hbc.getCelebrities();
		try {
			for(int i = 0;i<quantity;i++){
				Celebrity celeb = celebrities.get(randomNumbers.get(i));
				JSONObject json = new JSONObject();
				
				json.put("content",miscServ.getCarouselContentStringAsHtml("carousel/images/"+celeb.getUsername()+".jpg",celeb.getUsername()));
				json.put("content_button",miscServ.getCarouselContentButtonStringAsHtml("","<b>" + celeb.getFirstName() + " " + celeb.getLastName() + "</b><br>" + hbc.getLastTweetOfCelebrity(celeb.getUsername())));
				
				resultJson.put(json);
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return resultJson.toString();
	}
}
